<?php
/**
 * 举例：RDB订单和MYSQL订单
 * 抽象工厂模式用于生成产品族的工厂，所生成的对象是有关联的。
 * 如果抽象工厂退化成生成的对象无关联则成为工厂函数模式。
 * */
interface orderOperate{
    function saveDetail();
    function saveInfo();
}
class RDBOperateA implements orderOperate{
    function saveDetail()
    {
        echo "采用A服务器RDB保存订单详情";
    }
    function saveInfo()
    {
        echo "采用A服务器RDB保存订单信息";
    }
}
class RDBOperateB implements orderOperate{
    function saveDetail()
    {
        echo "采用B服务器RDB保存订单详情";
    }
    function saveInfo()
    {
        echo "采用B服务器RDB保存订单信息";
    }
}
class MysqlOperateA implements orderOperate{
    function saveDetail()
    {
        echo "采用A服务器mysql保存订单详情";
    }
    function saveInfo()
    {
        echo "采用A服务器mysql保存订单信息";
    }
}
class MysqlOperateB implements orderOperate{
    function saveDetail()
    {
        echo "采用B服务器mysql保存订单详情";
    }
    function saveInfo()
    {
        echo "采用B服务器mysql保存订单信息";
    }
}
abstract class factory{
    abstract function createRDBOperate();
    abstract function createMysqlOperate();
}
class factoryA extends factory{
    public function createRDBOperate(){
        return new RDBOperateA();
    }
    public function createMysqlOperate(){
        return new MysqlOperateA();
    }
}
class factoryB extends factory{
    public function createRDBOperate(){
        return new RDBOperateB();
    }
    public function createMysqlOperate(){
        return new MysqlOperateB();
    }
}
$operate = (new factoryA())->createMysqlOperate();
$operate->saveInfo();
$operate->saveDetail();